package com.hqully.smartfumehood.controller;

import com.github.pagehelper.PageInfo;
import com.hqully.smartfumehood.common.utils.ResultVoUtil;
import com.hqully.smartfumehood.common.vo.QueryVo;
import com.hqully.smartfumehood.common.vo.ResultVo;
import com.hqully.smartfumehood.common.websocket.UserWebSocketServer;
import com.hqully.smartfumehood.entity.AirData;
import com.hqully.smartfumehood.entity.FumeHoodData;
import com.hqully.smartfumehood.entity.SmokeData;
import com.hqully.smartfumehood.service.AirDataService;
import com.hqully.smartfumehood.service.FumeHoodDataService;
import com.hqully.smartfumehood.service.SmokeDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 设备数据前端控制器
 * <p>
 *
 * @author liulingyu
 * @date 2022/6/25 10:44
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/device-data")
@Slf4j
public class DevDataController extends BaseController{

    private final UserWebSocketServer webSocketServer;

    public DevDataController(UserWebSocketServer webSocketServer) {
        this.webSocketServer = webSocketServer;
    }
   @Autowired
   private FumeHoodDataService fumeHoodDataService;

   @Autowired
   private AirDataService airDataService  ;

   @Autowired
   private SmokeDataService smokeDataService  ;


    @PostMapping("/find-fume-hood-data")
    public ResultVo findAllFumeHoodData(@RequestBody QueryVo queryVo){

        PageInfo<FumeHoodData> fumeHoodDataList = fumeHoodDataService.findAllByVavId(queryVo);

        return ResultVoUtil.success(fumeHoodDataList);
    }


    @PostMapping("/find-air-data")
    public ResultVo findAllAirData(@RequestBody QueryVo queryVo){

        PageInfo<AirData> airDataList = airDataService.findAllAirDataByAirId(queryVo);

        return ResultVoUtil.success(airDataList);
    }


    @PostMapping("/find-smoke-data")
    public ResultVo findAllSmokeData(@RequestBody QueryVo queryVo){

        PageInfo<SmokeData> smokeDataList = smokeDataService.findAllSmokeDataByAirId(queryVo);

        return ResultVoUtil.success(smokeDataList);
    }
    @GetMapping("/send-command-data")
    public ResultVo testData(String shujv) {

        log.info("send-command -data {}",shujv);
        webSocketServer.sendTo(shujv,"device");


        return ResultVoUtil.success("处理成功",true);


    }
}
